let option = document.querySelector("option");
let select = document.querySelector("form > select");
let sesstion = document.querySelector(".sesstion");
let status = document.querySelector(".status");
let sesstionList = document.querySelector(".sesstion_list");
let statusList = document.querySelector(".status_list");

// 获取传来过的token
let token = sessionStorage.getItem("token");
let data = { "token": token }
let api = "http://newshopapi.0melon0.cn/api/f_user/chooselist"

console.log(token);

// 请求数据
ajax(api, data, "GET").then(res => {

    res.result.list.forEach(item => {
        select.innerHTML += `
    <option>${item.day_time}</option>
    `
    })
})

// 清空上次内容
select.innerHTML = '';
select.innerHTML = "<option>-请选择日期-</option>"
    // 下拉框change事件
select.addEventListener("change", () => {
    // 清空场次、状态
    sesstionList.innerHTML = '';
    statusList.innerHTML = '';

    // 获取参数
    // console.log(select.value);
    let api = "http://newshopapi.0melon0.cn/api/f_user/chooseday";
    let data = { "token": token, "day_time": select.value };
    // 请求数据
    ajax(api, data, "GET").then(res => {
        console.log(res);
        console.log(res.result.list);

        let day_time_arr = [];
        let show_id_arr = [];
        res.result.list.forEach(item => {
            // 把show_id存进数组
            show_id_arr.push(item.show_id)
            day_time_arr.push(item.day_time)

            // console.log(item);
            // 渲染时间
            sesstionList.innerHTML += `
      <p>${item.show_name}</p>`

<<<<<<< HEAD
      // 获取各个时间段的时间戳
      // console.log(item.day_time +" "+item.show_name.substr(-5));
      let minTime = new Date(item.day_time + " " + item.show_name.substr(0, 5)).getTime();
      let maxTime = new Date(item.day_time + " " + item.show_name.substr(-5)).getTime();
      let nowTime = new Date().getTime();
      // 判断时间戳

      console.log(minTime);
      
      if (maxTime > nowTime && nowTime < minTime) {
        // 渲染状态
        statusList.innerHTML += `
=======
            // 获取各个时间段的时间戳
            // console.log(item.day_time +" "+item.show_name.substr(-5));
            let minTime = new Date(item.day_time + " " + item.show_name.substr(0, 5)).getTime();

            // console.log(item.day_time + " " + item.show_name.substr(0, 5));


            let nowTime = new Date().getTime();
            // console.log(new Date());

            // 判断时间戳
            if (nowTime < minTime) {
                // 渲染状态
                statusList.innerHTML += `
>>>>>>> origin/0910LHL
      <p style="color:green">可预约</p>`

            } else {
                statusList.innerHTML += `
        <p style="color:red">不可预约</p>`
            }
        })

        // 获取p标签
        let pList = statusList.querySelectorAll("P");
        pList.forEach((item, index) => {
            item.addEventListener("click", (event) => {
                if (event.target.innerHTML == "可预约") {
                    // 把show.id取出来，并存到session
                    show_id = show_id_arr[index];
                    day_time = day_time_arr[index]
                        // console.log(show_id);

                    // 把参数存到session
                    sessionStorage.setItem("show_id", show_id);
                    sessionStorage.setItem("day_time", day_time);
                    location.href = 'finish.html'
                }
            })
        })
    })
})